﻿using System;
using SportTraining.Core.Domain;

namespace SportTraining.MVVM.ViewModel.Impl
{
    public class PaymentItemViewModel : ViewModelBase<PaymentItemViewModel>, IPaymentItemViewModel
    {
        public PaymentItemViewModel(IPayment payment)
        {
            Payment = payment;
        }

        #region Implementation of IPaymentItemViewModel
        public IPayment Payment { get; private set; }

        private int feeMoney;
        public int FeeMoney
        {
            get
            {
                return feeMoney;
            }
            set 
            { 
                feeMoney = value;

                Payment.FeeMoney = value;

                RestMoney = CalcRestMoney();

                FirePropertyChanged(type => type.FeeMoney);
            }
        }

        private int restMoney;
        public int RestMoney
        {
            get
            {
                return restMoney;
            }
            set
            {
                restMoney = value;

                FirePropertyChanged(type => type.RestMoney);
            }
        }

        public string SectionName
        {
            get { return Payment.Price.Section.ToString(); }
        }

        public DateTime SubscriptionDate
        {
            get { return Payment.SubscriptionDate; }
        }

        private int CalcRestMoney()
        {
            if ((Payment.Price.Cost - FeeMoney) < 0)
            {
                return 0;
            }

            return Payment.Price.Cost - FeeMoney;
        }

        #endregion
    }
}